<template>
  <div v-for="item in templateList" :key="item.id">
    <TemplateCard
      ref="demandCardRef"
      :form="item"
      @status-change="statusChange"
      @edit="edit"
      @del="del"
    >
    </TemplateCard>
  </div>
  <div class="card-plus-div">
    <a-card
      class="card-plus"
      :style="{ width: '360px', height: '188px' }"
      hoverable
      @click="goInternshipTemplateDetail()"
    >
      <icon-plus :size="48" />
    </a-card>
  </div>
</template>
<script setup lang="ts">
import { TEditInternshipTemplate } from '@/apis/human/base/variationManager/type';
import * as apiVariation from '@/apis/human/base/variationManager';
import { useRouter } from 'vue-router';
import TemplateCard from '@/views/Management/Human/BaseSetting/IntershipSetting/InternshipTemplate/components/index.vue';
const router = useRouter();
const templateList = ref<TEditInternshipTemplate[]>([]);
//去新增模板
const goInternshipTemplateDetail = (data?: TEditInternshipTemplate) => {
  let id = data && data.id! > 0 ? data.id : void 0;
  router.push({
    name: 'InternshipTemplateDetail',
    query: { id }
  });
};
//获取实习生证明模板列表
const getInternshipTemplateData = async () => {
  let res = await apiVariation.GetInternshipProofMode();
  templateList.value =
    (res as TEditInternshipTemplate) || ([] as TEditInternshipTemplate);
};
getInternshipTemplateData();
// 修改模板状态
const statusChange = async (data: TEditInternshipTemplate) => {
  let id = data && data.id! > 0 ? data.id : void 0;
  if (!id) return;
  await apiVariation.PostInternshipTemplateStatusOpen({ id });
  getInternshipTemplateData();
};
//编辑
const edit = (data: TEditInternshipTemplate) => {
  goInternshipTemplateDetail({ id: data.id });
};
//删除
const del = async (id: number) => {
  if (!id) return;
  await apiVariation.DelInternshipTemplateById({ id });
  getInternshipTemplateData();
};
</script>
<style lang="less" scoped>
.card-plus-div {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  .card-plus {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
}
.form-set {
  padding: 16px 0;
}
</style>
